package com.example.yk_lx.addmember;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import android.os.Bundle;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ToastUtils;
import com.example.yk_lx.R;
import com.example.yk_lx.baseMVVM.BaseActivity;
import com.example.yk_lx.databinding.ActivityAddmemberBinding;

@Route(path = "/app/AddmemberActivity")
public class AddmemberActivity extends BaseActivity<ActivityAddmemberBinding,AddmemberViewModel> {
    @Autowired
    String groupId;

    @Override
    protected int bindLayout() {
        return R.layout.activity_addmember;
    }

    @Override
    protected void initView() {
        ARouter.getInstance().inject(this);
        dataBinding.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewModel.addmember(groupId,new String[]{dataBinding.et.getText().toString()});
            }
        });
    }

    @Override
    protected void initData() {
        viewModel.success.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                ToastUtils.showLong(s);
                finish();
            }
        });
        viewModel.fail.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                ToastUtils.showLong(s);
            }
        });
    }

    @Override
    protected Class<AddmemberViewModel> getViewModel() {
        return AddmemberViewModel.class;
    }
}